
package JET.graphics.elements;

import JET.geom.MassPolygon;
import JET.geom.Polygon;
import JET.geom.Vec2d;
import JET.physics.Mass;
import JET.physics.PhysicsHelper;
import java.awt.Color;
import java.util.Collection;

/**
 *
 * @author 057Ry
 */
public class Face {

    private MassPolygon massPolygon;
    private Polygon texturePolygon;

    private boolean visible = true;
    private Color color;

    // Helper variables
    private double[] xPoints, yPoints;

    public Face(Collection<Mass> mCol) {
        set(mCol);
    }

    public void set(Collection<Mass> mCol) {
        massPolygon = new MassPolygon(mCol);

        Vec2d center = PhysicsHelper.getGeomCenterOfMasses(mCol);
        texturePolygon = new Polygon();
        for(Mass m : mCol)
            texturePolygon.add(m.getPosition().getSubbed(center));

        xPoints = new double[mCol.size()];
        yPoints = new double[mCol.size()];

        color = Color.GREEN;
    }

    public double getX(int index) {
        return massPolygon.getMass(index).getPosition().getX();
    }
    
    public double getY(int index) {
        return massPolygon.getMass(index).getPosition().getY();
    }

    public double[] getXPoints() {
        for(int i=0; i<massPolygon.getCount(); i++)
            xPoints[i] = massPolygon.getMass(i).getPosition().getX();

        return xPoints;
    }

    public double[] getYPoints() {
        for(int i=0; i<massPolygon.getCount(); i++)
            yPoints[i] = massPolygon.getMass(i).getPosition().getY();

        return yPoints;
    }

    public int getPointsCount() { return massPolygon.getCount(); }

    public boolean isVisible() {return visible;}
    public void setVisible(boolean v) {visible = v;}

    public Color getColor() {return color;}
    public void setColor(Color c) {color = c;}

    public String toString() {
        return "Face[n:"+getPointsCount()+"]->"+massPolygon;
    }
}
